    'use strict';
    app.controller('ChargeOfStoreFormController', ['$scope', '$http', '$state', function($scope, $http, $state) {
        $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
        $(".datetimepicker_").datetimepicker({
            format: 'yyyy-mm-dd',
            language:"cn",
            weekStart: 1,
            todayBtn:  "linked",
            autoclose: true,
            startView: 4,
            minView: 2,
            todayHighlight: true,
            endDate : new Date()
        });
        $scope.chargeOfStore = {
            userType:"3",
            headImageUrl:""
        };
        $scope.authError = null;
        $scope.registerChargeOfStore = function() {
            $scope.authError = null;
            // Try to create
            $http.post('/user/registerchargeofstore', $.param($scope.chargeOfStore))
                .then(function(response) {
                    if ( response.data) {
                        $state.go('access.waitingaudit');
                    }else{
                        $scope.authError = response;
                    }
                }, function(x) {
                    $scope.authError = 'Server Error';
                });
        };
        $scope.changeRole=function(){
            $state.go("access.chooserole");
        }

        $scope.uploadPhotoImage=function(target){
            if(!target|| !target.files[0]){
                return;
            }
            var file=target.files[0];
            var data = new FormData();
            data.append("file", file);
            data.append("key",file['name']); //唯一性参数
            $.ajax({
                data: data,
                type: "POST",
                url: "/file/uploadimage",
                cache: false,
                contentType: false,
                processData: false,
                success: function(result) {
                    if(!result){
                        alert("上传失败！");
                        return;
                    }else{
                        console.log("上传成功！");
                        var resultData=eval("("+result+")");
                        $(target).prev().attr("value",resultData.url);
                        $(target).next().attr("src",resultData.url);
                        $scope.chargeOfStore.headImageUrl=resultData.url;
                    }
                },
                error:function(){
                    alert("上传失败！");
                    return;
                }
            });
        }
    }]);
